package experiment;
import java.util.Iterator;

public strictfp class ValueSet
{

	public boolean isEnumerated = false ;
	public java.util.List values ;

	public boolean isStepped = false ;
	public Double first ;
	public Double last ;
	public Double step ;

	public ValueSet() {}
	
    public ValueSet(double min, double max, double levels)
    {
        isStepped = true;
        first = min;
        last = max;
        step = Math.abs(min - max) / levels;
    }

	public Iterator iterator()
	{
		if( isEnumerated )
		{
			if( isStepped )
			{
				throw new IllegalStateException() ;
			}
			return values.iterator() ;
		}
		else
		{
			if( ! isStepped )
			{
				throw new IllegalStateException() ;
			}
			return new SteppedIterator() ;
		}
	}

	class SteppedIterator
		implements Iterator
	{
		private int steps = -1 ;
		public boolean hasNext()
		{
			return nextValue().doubleValue() <= last.doubleValue() ;
		}
		public Object next()
		{
			Double result = nextValue() ;
			steps++ ;
			return result ;
		}
		public void remove()
		{
			throw new UnsupportedOperationException() ;
		}
		private Double nextValue()
		{
			return new Double
				( first.doubleValue() + ( steps + 1 ) * step.doubleValue() ) ;
		}
	}

}
